<?php

use yii\db\Migration;

class m161102_082844_after_mechanic extends Migration
{
    private function createDbs(){
        $dbs = [];
        $dbs_info =\Yii::$app->params['db'];
        foreach($dbs_info as $k=>$v){
            $dbs[$k] = \Yii::createObject($v);
        }
        return $dbs;
    }

    // Use safeUp/safeDown to run migration code within a transaction
    public function safeUp()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->addColumn('{{%mechanic}}', 'enrollment_ratio', 'double(10,2) default 0 comment \'招生比例，（总课时的百分数）\'');
            $this->addColumn('{{%mechanic}}', 'return_ratio', 'double(10,2) default 0 comment \'课时费返现比例，（课时费的百分比）\'');
            $this->addColumn('{{%mechanic}}', 'reduction', 'SMALLINT(4) default 0 comment \'减免课时费的课次数\'');
        }
    }

    public function safeDown()
    {
        $dbs = $this->createDbs();
        foreach($dbs as $v) {
            $this->db = $v;
            $this->dropColumn('{{%mechanic}}', 'enrollment_ratio');
            $this->dropColumn('{{%mechanic}}', 'return_ratio');
            $this->dropColumn('{{%mechanic}}', 'reduction');
        }
    }

}
